<template>
  <div class="home">
    <h1>主页</h1>
    <div class="content">
      <el-button type="danger" @click="handleLogout">退出登录</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { logout } from '@/api/user'

const router = useRouter()

const handleLogout = async () => {
  try {
    await logout()
    // 清除本地存储的token
    localStorage.removeItem('token')
    ElMessage.success('退出登录成功')
    // 跳转到登录页
    router.push('/login')
  } catch (error) {
    console.error('退出登录失败:', error)
    ElMessage.error('退出登录失败，请重试')
  }
}
</script>

<style scoped>
.home {
  padding: 20px;
}

.content {
  margin-top: 20px;
}
</style> 